﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SCG.SolarVengeanceEngine;
using SCG.WinForms;
using SCG.TurboSprite;

namespace SCG.SolarVengeance
{
    public partial class InfoPanel : BasePanel
    {
        //constructors
        public InfoPanel()
            : base()
        {
            InitializeComponent();
        }

        //ensure proper sizing
        public override void Initialize()
        {
            elastic.ForceResize();
        }

        //update each impulse
        public override void ImpulseUpdate()
        {
            Image img = null;
            SVMapObject svm = Game.GetObjectAt(GamePage.CursorLocation.X, GamePage.CursorLocation.Y);
            if (svm == null)
            {
                elastic.Visible = true;
                switch (Game.GetTerrain(GamePage.CursorLocation.X, GamePage.CursorLocation.Y))
                {
                    case 'n':
                    case 'N':
                        lblInfo.Text = "Nebula";
                        lblDescription.Text = "Nebula hides objects within.  StarShips, StarSystems " +
                        "and other objects in a Nebula are not visible to Scanners.  Also, Scanners do " +
                        "not operate when their source is within a Nebula.";
                        img = NebulaImage;
                        break;
                    default:
                        elastic.Visible = false;
                        break;
                }
            }
            else if (svm.DiscoveredByCurrentPlayer || svm.VisibleToCurrentPlayer)
            {
                elastic.Visible = true;
                if (svm is Wormhole)
                {
                    lblInfo.Text = "Wormhole";
                    lblDescription.Text = "Wormholes are one-way tunnels through space.  " +
                    "When a StarShip enters a Wormhole, it is deposited at the Wormhole's " +
                    "exit point, which can be anywhere on the map.";
                    img = WormholeImage;
                }
                else if (svm is Pulsar)
                {
                    lblInfo.Text = "Pulsar";
                    lblDescription.Text = "Pulsars are rapidly spinning high energy neutron stars.  " +
                    "StarShips can use the energy emitted by a Pulsar to repair themselves.  " +
                    "Any StarShip that moves next to a Pulsar has any damage immediately repaired.";
                    img = PulsarImage;
                }
                else if (svm is BlackHole)
                {
                    lblInfo.Text = "Black Hole";
                    lblDescription.Text = "Black Holes exert tremendous gravitational force that pulls in " +
                    "any StarShip within reach.  StarShips that are drawn into the Black Hole's center are " +
                    "obliterated.";
                    img = BlackHoleImage;
                }
                else if (svm is UDO)
                {
                    UDO udo = svm as UDO;
                    if (udo.VisibleToCurrentPlayer)
                    {
                        lblInfo.Text = udo.Name;
                        lblDescription.Text = udo.Description;
                        UDOSprite udos = (UDOSprite)udo.Tag;
                        img = ImageUtils.ResizeBitmap(udos.Bitmap, 60, 60, true);
                    }
                    else
                        elastic.Visible = false;
                }
                else
                    elastic.Visible = false;
            }
            else
                elastic.Visible = false;
            if (img != null)
                picImage.Image = img;
            Refresh();
        }

        private static Image NebulaImage;
        private static Image WormholeImage;
        private static Image PulsarImage;
        private static Image BlackHoleImage;

        //load images
        private void InfoPanel_Load(object sender, EventArgs e)
        {
            NebulaImage = Bitmap.FromFile("Images\\Nebula.bmp");
            NebulaImage = ImageUtils.ResizeBitmap(NebulaImage, 60, 60, false);
            WormholeImage = Bitmap.FromFile("Images\\Wormhole.bmp");
            WormholeImage = ImageUtils.ResizeBitmap(WormholeImage, 60, 60, true);
            PulsarImage = Bitmap.FromFile("Images\\Pulsar.bmp");
            PulsarImage = ImageUtils.ResizeBitmap(PulsarImage, 60, 60, true);
            BlackHoleImage = Bitmap.FromFile("Images\\BlackHoleThumb.bmp");
            BlackHoleImage = ImageUtils.ResizeBitmap(BlackHoleImage, 60, 60, true);
        }
    }
}
